//package com.zrrt.game;
//
//import java.sql.Connection;
//import java.sql.Date;
//import java.sql.PreparedStatement;
//import java.sql.ResultSet;
//import java.sql.SQLException;
//import java.sql.Statement;
//import java.text.SimpleDateFormat;
//import java.util.Vector;
//
//import javax.naming.InitialContext;
//import javax.sql.DataSource;
//
//public class DBOperate {
//
//	static DataSource dataSource;
//
//	Connection conn;
//
//
//	PreparedStatement ps;
//
//	private void getDataSource() {
//		try {
//			InitialContext initialContext = new InitialContext();
//			dataSource = (DataSource) initialContext
//				//	.lookup("java:comp/env/jdbc/games");
//			.lookup("java:comp/env/jdbc/mysql");
//			
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//	}
//
//	private void openDB() {
//		try {
//			if (dataSource == null) {
//				getDataSource();
//			}
//
//			if (dataSource != null) {
//				conn = dataSource.getConnection();
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//	}
//
//	private void closeDB() {
//		try {
//			if (conn != null) {
//				conn.close();
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//	}
//
////	public void getinfo(String model) {
////		System.out.println("1");
////		openDB();
////		System.out.println("2");
////		if (conn != null) {
////			System.out.println("3");
////			try {
////				Statement sm = conn.createStatement(
////						ResultSet.TYPE_SCROLL_INSENSITIVE,
////						ResultSet.CONCUR_READ_ONLY);
////				ResultSet rs = sm
////						.executeQuery("SELECT * FROM factory_table where model='"
////								+ model + "'");
////				if (rs.next()) {
////					System.out.println(rs.getString(2));
////					System.out.println(rs.getInt(3));
////					System.out.println(rs.getString(4));
////					System.out.println(rs.getString(5));
////				}
////				rs.close();
////				sm.close();
////			} catch (SQLException e) {
////				// TODO Auto-generated catch block
////				e.printStackTrace();
////			} finally {
////				closeDB();
////			}
////
////		}
////	}
//
//	public void addLog(String url, String ip) {
//		String model = url.substring(url.lastIndexOf("/") + 1, url.length());
//		model = model.substring(0, model.indexOf("."));
//		Date date = new Date(System.currentTimeMillis());
//		String dateStr = DataToString(date);
//		try {
//			openDB();
//			if (conn != null) {
//				String sql = "insert into game_access_log value (null,'"
//						+ model + "','" + url + "','" + dateStr + "','" + ip
//						+ "')";
//				ps = conn.prepareStatement(sql);
//				ps.execute();
//				ps.close();
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
//		} finally {
//			closeDB();
//		}
//	}
//
////	public void addGamedownLoad(String gamename, String url, String ip) {
////		Date date = new Date(System.currentTimeMillis());
////		String dateStr = DataToString(date);
////		try {
////			boolean ishave = false;
////			if (servlet.ve.size() == 0) {
////				servlet.ve.addElement(gamename + " " + ip);
////			} else if (servlet.ve.size() > 0) {
////				for (int i = 0; i < servlet.ve.size(); i++) {
////					if ((gamename + " " + ip).equals(servlet.ve.elementAt(i).toString())) {
////						ishave = true;
////						break;
////					}
////				}
////				if (!ishave) {
////					if (servlet.ve.size() > 9) {
////						servlet.ve.removeElementAt(0);
////					}
////					servlet.ve.addElement(gamename + " " + ip);
////					openDB();
////					if (conn != null) {
////						String sql = "insert into game_count value (null,'"
////								+ gamename + "','" + url + "','" + dateStr
////								+ "','" + ip + "')";
////						ps = conn.prepareStatement(sql);
////						ps.execute();
////						ps.close();
////					}
////				}
////			}
////
////		} catch (Exception e) {
////			e.printStackTrace();
////		} finally {
////			closeDB();
////		}
////	}
////	public void adddownLoad(String gamename, String url, String ip) {
////		Date date = new Date(System.currentTimeMillis());
////		String dateStr = DataToString(date);
////		try {
////						openDB();
////					if (conn != null) {
////						String sql = "insert into game_count value (null,'"
////								+ gamename + "','" + url + "','" + dateStr
////								+ "','" + ip + "')";
////						ps = conn.prepareStatement(sql);
////						ps.execute();
////						ps.close();
////					}
////				} catch (Exception e) {
////			e.printStackTrace();
////		} finally {
////			closeDB();
////		}
////	}
//
//	private String DataToString(Date date) {
//		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
//		sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//		String newDate = sdf.format(date);
//		return newDate;
//	}
//}
